﻿window.jqkit = {
	plugins: {},
    components: {}
};

/**
 * Returns true if the specified value is not undefined.
 * WARNING: Do not use this to test if an object has a property. Use the in operator instead. Additionally, this function assumes that the global
 * undefined variable has not been redefined.
 * @param {*} value Variable to test.
 * @return {boolean} Whether variable is defined.
 */
jqkit.isDefined = function(value) {
	return typeof(value) !== 'undefined';
}

/**
 * Returns true if the specified value is defined and not null.
 * @param {*} value Variable to test.
 * @return {boolean} Whether variable is defined and not null.
 */
jqkit.isDefinedAndNotNull = function(value) {
	return typeof(value) !== 'undefined' && value !== null;
};

/**
 * Returns true if the specified value is a number.
 * @param {*} value Variable to test.
 * @return {boolean} Whether variable is a number.
 */
jqkit.isNumber = function(value) {
	return typeof(value) === 'number';
};

/**
 * Executes a function given its name as a string. Accepts namespaced functions and any number of function arguments.
 * @context {object} The context of which to apply to the executing function.
 * @param {string} name The name of the function to execute.
 * @param {object} opt_context The context associated with the given function name.
 * @param {*} opt_var_args Any number of parameters to pass to the function as input.
 * @return {*} The result of the function which was executed.
*/
jqkit.executeByName = function(name, opt_context, opt_var_args) {
    var args = Array.prototype.slice.call(arguments, 2);
    var namespaces = name.split('.');
    var func = namespaces.pop();
    opt_context = opt_context || window;
    for (var i = 0; i < namespaces.length; i++) {
        opt_context = opt_context[namespaces[i]];
    }
    return opt_context[func].apply(this, args);
};